package com.yanqu.road.entity.activity.foxcard.config;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@FieldTypeAnnotation(tableName = "t_s_activity_fox_round")
public class FoxCardRoundConfig {
    @FieldTypeAnnotation(select = true, orderASC = true, isIndex = true)
    private int activityId;
    @FieldTypeAnnotation(desc = "回合id", isIndex = true)
    private int id;
    @FieldTypeAnnotation(desc = "过关分数")
    private BigInteger passScore = BigInteger.ZERO;
    @FieldTypeAnnotation(desc = "是否有限制")
    private int isLimit;
    @FieldTypeAnnotation(desc = "奖励")
    private String reward;
    @FieldTypeAnnotation(desc = "形象id")
    private String appearanceId;
    @FieldTypeAnnotation(desc = "金币奖励")
    private int goldReward;

    private Map<Integer, List<List<Property>>> rewardMap = new HashMap<>();

    public FoxCardRoundConfig(ResultSet rs) throws SQLException {
        this.activityId = rs.getInt("activityId");
        this.id = rs.getInt("id");
        this.passScore = new BigDecimal(rs.getString("passScore")).toBigInteger();
        this.isLimit = rs.getInt("isLimit");
        this.reward = rs.getString("reward");
        this.appearanceId = rs.getString("appearanceId");
        this.goldReward = rs.getInt("goldReward");
        String[] strings = this.reward.split("@");
        for (int stageId = 1; stageId <= strings.length; stageId++) {
            List<List<Property>> list = PropertyHelper.parseNewStringToPropertyList(strings[stageId-1]);
            this.rewardMap.put(stageId, list);
        }
    }

    public int getActivityId() {
        return activityId;
    }

    public int getId() {
        return id;
    }

    public BigInteger getPassScore() {
        return passScore;
    }

    public int getIsLimit() {
        return isLimit;
    }

    public String getReward() {
        return reward;
    }

    public String getAppearanceId() {
        return appearanceId;
    }

    public int getGoldReward() {
        return goldReward;
    }

    public Map<Integer, List<List<Property>>> getRewardMap() {
        return rewardMap;
    }

    public Property getReward(int stageId) {
        return PropertyHelper.randomPropertyByListList(rewardMap.getOrDefault(stageId, new ArrayList<>()));
    }
}